import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import path from 'path';
import tailwindcss from 'tailwindcss';
import autoprefixer from 'autoprefixer';
import viteCompression from 'vite-plugin-compression';
import fileUpload from './src/utils/upload.js'
import exportJson from "./src/utils/exportJson.js";

export default defineConfig({
    resolve: {
        extensions: ['.vue', '.ts', '.js', '.json'],
        alias: {
            '@': path.resolve(__dirname, '.', 'src'),
            '@img': path.resolve(__dirname, '.', 'src/assets/img'),
            '@utils': path.resolve(__dirname, '.', 'src/utils'),
        },
    },
    // 运行端口
    server: {
        port: 5100,
        watch: {
            // 阻止热更新！不然上传图片会让项目重新运行
            ignored: [
                '**/src/assets/img/uploads/**',
                '**/static/uploads/**',
                '**/node_modules/**',
                '**/.git/**'
            ]
        }
    },
    plugins: [
        vue(),
        fileUpload(),
        exportJson(),
        viteCompression({
            // 压缩
            verbose: true,
            disable: false,
            threshold: 10240,
            algorithm: 'gzip',
            ext: '.gz',
        }),
    ],
    css: {
        postcss: {
            plugins: [tailwindcss, autoprefixer],
        },
    },
});
